const fs = require('fs');
const path = require('path');
const os = require('os');


const asyncUpload = async (uploadPath, file, AllowSuffix=[] ) => {
    const reader = fs.createReadStream(file['path']);
    let filePath = path.resolve(uploadPath,  file['name']);
    let dir = path.dirname(filePath);
    if(!fs.existsSync(dir)){
        fs.mkdirSync(dir)
    }
    // 创建可写流
    const upStream = fs.createWriteStream(filePath);
    // 可读流通过管道写入可写流
    reader.pipe(upStream);
    return true;
}

module.exports = asyncUpload
